# -*- coding: utf-8 -*-
# @Time:    2023-05-29 15:45
# @Author:  geng
# @Email:   yonglonggeng@163.com
# @WeChat:  superior_god
# @File:    05batchRename.py
# @Project: tag2label
# @Package: 
# @Ref:
import os


def rename_by_tag(tag):
    json_files = [file.split(".")[0] for file in os.listdir("./") if file.split(".")[-1] == "json"]

    for json_file in json_files:
        print(json_file)
        os.rename(json_file + ".json", tag + json_file + ".json")
        os.rename(json_file + ".jpg", tag + json_file + ".jpg")


def recover_name(tag):
    json_files = [file.split(".")[0] for file in os.listdir("./") if file.split(".")[-1] == "json"]

    for json_file in json_files:
        print(json_file)
        new_json_file = json_file.split(tag)[-1]
        os.rename(json_file + ".json", new_json_file + ".json")
        os.rename(json_file + ".jpg", new_json_file + ".jpg")
    # os.rename(json_file + ".json", tag + json_file + ".json")


if __name__ == '__main__':
    rename_by_tag(tag="two_")
    # recover_name(tag="two_")
